package adapter

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"migration-tool/common"
	"migration-tool/target"
	"testing"
)

const (
	TestDefaultConfigPath = common.GlobalDefaultConfigPath
)

func TestWriteData(t *testing.T) {
	cfg, err := common.ParseConfig(TestDefaultConfigPath)
	assert.Equal(t, err, nil)

	repoInfo := RepoInfo{
		RepoId:           2754725,
		RepoGroupName:    "agit",
		RepoName:         "test_migration",
		CodeCloneHttpUrl: "http://gitlab.alibaba-inc.com/agit/test_migration.git",
		WikiEnable:       true,
	}

	writeDataArgs := DataArgs{
		ExportDataDir:      cfg.BaseConfig.ExportDataDir,
		ExportPlatformName: AonePlatformName,
		FileName:           BinFileNameRepoMembers,
		FilePathTmpl:       ExportDataFileTmpl,
		RepoInfo:           &repoInfo,
		Data:               nil,
	}

	_, err = WriteProtoData(writeDataArgs)
	assert.Equal(t, err, nil)
}

func TestReadData(t *testing.T) {
	cfg, err := common.ParseConfig(TestDefaultConfigPath)
	assert.Equal(t, err, nil)

	//repoInfo := RepoInfo{
	//	RepoId:           2754725,
	//	RepoGroupName:    "agit",
	//	RepoName:         "test_migration",
	//	CodeCloneHttpUrl: "http://gitlab.alibaba-inc.com/agit/test_migration.git",
	//	WikiEnable:       true,
	//}

	repoInfo := RepoInfo{
		RepoId:           1549172,
		RepoGroupName:    "agit",
		RepoName:         "satellite",
		CodeCloneHttpUrl: "http://gitlab.alibaba-inc.com/agit/satellite.git",
		WikiEnable:       true,
	}

	var data target.CodeupMemberList
	readDataArgs := DataArgs{
		ExportDataDir:      cfg.BaseConfig.ExportDataDir,
		ExportPlatformName: AonePlatformName,
		FileName:           BinFileNameRepoMembers,
		FilePathTmpl:       ExportDataFileTmpl,
		RepoInfo:           &repoInfo,
		Data:               &data,
	}

	_, err = ReadProtoData(readDataArgs)
	assert.Equal(t, err, nil)
	fmt.Println(data.RepoMember)
}
